home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGBLER / WHIZZARD.LZH / XREP.ASM < prev    next >
Assembly Source File  |  1984-07-12  |  7KB  |  269 lines

  1. COMMENT *
  2.  
  3.                  CLUBware  (tm)
  4.  
  5.       XREP repeates an input character some number of times.
  6.           The string starts at the current cursor position
  7.           and after the string is written to the screen
  8.           the cursor position is updated to just after the
  9.           string.
  10.  
  11.            Copyright 1984 Rayhawk Automation N.W. Inc
  12.                   P.O. Box 1427
  13.                   Beaverton, Oregon   97075
  14.  
  15.       Algorithm:
  16.           1) load type of crt display from 0000:463
  17.           2) load current position from 0000:0450
  18.           3) load count of characters to write
  19.           4) load character to write
  20.           5) address the screen segment
  21.           6) move string to screen segment while synchronizing
  22.               with horizontal retrace
  23.           7) update cursor position
  24.  
  25.  
  26.       CALL    XREP ( FLAG% , CHARACTER$ , COUNT% , ATTRIBUTE% )
  27.  
  28.           FLAG%       environment flag
  29.                   = 0 means under basic interpreter
  30.                   = 1 means under compiled basic not /O
  31.                   = 2 means under compiled basic with /O
  32.                   = 3 means under compiled business basic
  33.  
  34.           COUNT%  number of times to repeat the character
  35.  
  36.           CHARACTER$  character to write to screen
  37.  
  38.           ATTRIBUTE%  attribute for character
  39.  
  40.  
  41.                                           *
  42.  
  43. ;______________________________________________________________________________
  44.  
  45. ;  Normal assembly directives
  46.  
  47. CODE      SEGMENT PARA PUBLIC 'CODE'
  48.  
  49.       ASSUME  CS:CODE
  50.  
  51.       EXTRN   $PUTCPOS:FAR
  52.  
  53.       PUBLIC  XREP
  54.  
  55. ATTRIBUTE      EQU  WORD PTR [BP+6] ; address of string descriptor on stack
  56.  
  57. CHAR_COUNT      EQU  WORD PTR [BP+8] ; address of character count on stack
  58.  
  59. STRING_DESC      EQU  WORD PTR [BP+10] ; address of string descriptor on stack
  60.  
  61. ENV_FLAG      EQU  WORD PTR [BP+12] ; address of environment flag on stack
  62.  
  63. ;______________________________________________________________________________
  64.  
  65. XREP      PROC      FAR
  66.  
  67.       PUSH      BP               ; address parameters on stack
  68.       MOV      BP,SP
  69.  
  70.       PUSH      AX               ; save all registers used,
  71.       PUSH      BX
  72.       PUSH      CX
  73.       PUSH      DX
  74.       PUSH      SI
  75.       PUSH      DI
  76.       PUSH      ES
  77.  
  78.  
  79. ;      ...      0) load environment flag showing compiled or interpreted
  80.  
  81.       MOV      SI,ENV_FLAG           ; load address of environment flag
  82.       MOV      SI,WORD PTR [SI]     ; load flag itself
  83.  
  84.  
  85.  
  86. ;      ...      1) load type of crt display from 0000:463
  87.  
  88.       SUB      AX,AX              ; address system area
  89.       MOV      ES,AX
  90.  
  91.       MOV      DX,WORD PTR ES:[463h]      ; load address of display adapter
  92.       ADD      DX,6                 ; address crt status port
  93.  
  94.  
  95.  
  96. ;      ...      2) load current position from 0000:0450 if compiled
  97. ;              or from DS:[0056h] if interpreted
  98.  
  99.       CMP      SI,0               ; check environment flag
  100.       JNE      COMPILED
  101.  
  102.       MOV      CX,WORD PTR DS:[0056h]   ; load from basic space
  103.       XCHG      CL,CH            ; basic has it reversed
  104.       DEC      CL               ; basic starts count from 1
  105.       DEC      CH               ;  instead of zero
  106.       JMP      SHORT CALC_POSITION
  107.  
  108. COMPILED:
  109.       MOV      CX,WORD PTR ES:[450h]    ; load current position
  110.                        ;  from system space
  111. CALC_POSITION:
  112.       SUB      AH,AH            ; isolate row number in AX
  113.       MOV      AL,CH
  114.       MOV      BL,80            ; multiply row by 80 bytes per row
  115.       MUL      BL
  116.       SUB      CH,CH            ; add in column number
  117.       ADD      AX,CX
  118.  
  119.       MOV      DI,AX
  120.       SHL      DI,1               ; multiply by 2 to account
  121.                        ;  for attribute bytes
  122.  
  123.  
  124.  
  125. ;      ...      3) load count of characters to write
  126.  
  127.       MOV      BX,CHAR_COUNT        ; load address of character count
  128.       MOV      CX,WORD PTR DS:[BX]
  129.  
  130.  
  131. ;      ...      4) load character to write
  132. ;               note that each of the modes supported has their
  133. ;               own format for the string descriptor
  134.  
  135.       MOV      BX,STRING_DESC       ; load address of string descriptor
  136.       CMP      SI,0               ; running compiled?
  137.       JNE      IS_COMPILED
  138.       MOV      BX,WORD PTR [BX+1]   ; load offset of string
  139.       JMP      SHORT LOAD_CHAR
  140.  
  141. IS_COMPILED:
  142.       MOV      BX,WORD PTR [BX+2]   ; load offset of string
  143.  
  144.       CMP      SI,3
  145.       JNE      LOAD_CHAR
  146.  
  147.       ADD      BX,3               ;  Support BBC String format
  148.  
  149. LOAD_CHAR:
  150.  
  151.       MOV      AL,BYTE PTR [BX]     ; load the character itself
  152.  
  153.  
  154. ;      ...      4) load attribute for character
  155.  
  156.       MOV      BX,ATTRIBUTE           ; load address of attribute
  157.       MOV      BH,BYTE PTR DS:[BX]  ; load the attribute itself
  158.       MOV      BL,AL            ; move in the character
  159.  
  160.  
  161. ;      ...      5) address the screen segment
  162.  
  163.       MOV      AX,0B000h           ; screen seg for monochrome card
  164.       CMP      DX,03DAh           ; is this a graphic card?
  165.       JNE      MONOCHROME
  166.  
  167.       MOV      AX,0B800h           ; load screen seg for graphic card
  168.  
  169. MONOCHROME:
  170.  
  171.       MOV      ES,AX            ; address the screen buffer
  172.  
  173.  
  174. ;      ...      6) move string to screen while synchronizing
  175. ;              with horizontal retrace
  176.  
  177. DISPLAY_LOOP:
  178.  
  179.       CLI
  180. HSYNC_WAIT1:
  181.       IN      AL,DX            ; check for horizontal retrace
  182.       TEST      AL,1
  183.       JNZ      HSYNC_WAIT1           ; wait for retrace
  184. HSYNC_WAIT2:
  185.       IN      AL,DX            ; check for horizontal retrace
  186.       TEST      AL,1
  187.       JZ      HSYNC_WAIT2           ; wait for retrace
  188.  
  189.       MOV      AX,BX
  190.       STOSW                ; store character and attribute
  191.       STI
  192.  
  193.       CMP      DI,4000
  194.       JL      NOT_OFF_PAGE
  195.       MOV      DI,0               ; start at top again
  196. NOT_OFF_PAGE:
  197.  
  198.       LOOP      DISPLAY_LOOP           ; repeat cx times
  199.  
  200.  
  201. ;      ...      7) update cursor position
  202.  
  203.       MOV      AX,DI            ; load current position
  204.       SHR      AX,1               ; discount attribute bytes
  205.       SUB      DX,DX            ; no sign in this division
  206.       MOV      BX,80            ; divide by nmbr of chars per row
  207.       DIV      BX
  208.       MOV      DH,AL            ; store row number
  209.                        ; column number already in DL
  210.       MOV      BH,0               ; assume page 0
  211.       MOV      AH,2               ; request new position
  212.       INT      10h
  213.  
  214.       XCHG      DH,DL            ; basic likes it reversed
  215.       INC      DL               ; basic starts count from 1
  216.       INC      DH               ;  instead of zero
  217.  
  218.       MOV      SI,ENV_FLAG           ; load address of environment flag
  219.       CMP      WORD PTR DS:[SI],0   ; examine flag
  220.       JE      NOT_COMPILED
  221.  
  222.       CMP      WORD PTR DS:[SI],3   ; business basic?
  223.       JE      RET_TO_BASIC
  224.  
  225.       CMP      WORD PTR DS:[SI],2   ; compiled with /O?
  226.       JE      WITH_SLASH_O
  227.  
  228.                                     ; FLAG = 1
  229.       MOV      WORD PTR DS:[87h],DX ; store screen address
  230.       JMP      SHORT RET_TO_BASIC
  231.  
  232.  
  233. WITH_SLASH_O:                                ; FLAG = 2
  234.       MOV      DI,SEG $PUTCPOS     ; address put cursor routine
  235.       MOV      ES,DI
  236.       MOV      DI,OFFSET $PUTCPOS
  237.       MOV      DI,WORD PTR ES:[DI+2]  ; load offset of cursor storage
  238.       MOV      WORD PTR DS:[DI],DX     ; store new cursor position
  239.       JMP      SHORT RET_TO_BASIC
  240.  
  241.  
  242. NOT_COMPILED:                                ; FLAG = 0
  243.       MOV      WORD PTR DS:[0056h],DX ; store new cursor position
  244.  
  245.  
  246. RET_TO_BASIC:                                ; FLAG = 3
  247.  
  248.  
  249.  
  250.  
  251.       POP      ES
  252.       POP      DI
  253.       POP      SI
  254.       POP      DX
  255.       POP      CX
  256.       POP      BX
  257.       POP      AX
  258.       POP      BP
  259.       RET      8
  260.  
  261.  
  262. XREP      ENDP
  263.  
  264. ;______________________________________________________________________________
  265.  
  266. CODE      ENDS
  267.  
  268.       END
  269.